<?php

  class Timer {  
    
    static $times = array();
    
    
    # Starts timer
    static function reset($time = false) {
      if ($time == false) {
        $time = microtime(true);
      }  
      self::$times = array();
      self::$times[0] = $time;
    }
    
    # Sets midtime 
    static function set($time_number = false) {
      self::$times[$time_number] = microtime(true);
    }
    
    
    
    # Gets timer time
    static function get($time_number_from = 0, $time_number_to = false, $format = "%01.4f") {
      if ($time_number_to == false) {
        $time_to = microtime(true);
      } else {
        $time_to = self::$times[$time_number_to];
      }
      $time_from = self::$times[$time_number_from];
      
      
      $time = $time_to - $time_from;
      
      
      if ($format == false) {
        return $time;
      } else {
        return sprintf($format, $time);
      }
    }
    
  }
  
?>